package plugin;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * Fenster "Warte auf Simulator-Start"
 * 
 * @author Duncyo
 * 
 */
public class ConnectionWindow extends JFrame {
	private static final long serialVersionUID = 1L;
	private JPanel pane;
	private Font font = new Font("Dialog", Font.BOLD, 12);
	private Image appicon = Toolkit.getDefaultToolkit().createImage(
			"./src/plugin/images/train_icon.png");
	private JLabel label;

	protected ConnectionWindow() {
		this.setUndecorated(true);
		this.pane = new JPanel();
		pane.setLayout(new GridLayout(2, 1));
		label = new JLabel("Verbinde mit Stellwerk-Simulator");
		label.setFont(font);
		pane.add(label);
		pane.setBorder(BorderFactory.createLineBorder(Color.GRAY, 5));
		label.setIcon(new ImageIcon("./src/plugin/images/wait.gif"));
		label.setHorizontalAlignment(JLabel.CENTER);
		JButton button = new JButton("Abbrechen!");
		button.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println("Verbindungsversuch abgebrochen, Plugin beendet");
				System.exit(0);
			}
		});
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent _) {
				System.out.println("Verbindungsversuch abgebrochen, Plugin beendet");
				System.exit(0);
			}
		});
		pane.add(button);
		button.setFont(font);
		button.setFocusPainted(false);
		this.setContentPane(pane);
		this.setPreferredSize(new Dimension(500, 100));
		pack();
		setLocationRelativeTo(null);
		setVisible(true);
		setTitle("STS Analyse Plugin: Verbinden");
		this.setIconImage(appicon);
		repaint();
	}

	protected void waitForSim() {
		label.setText("Warte auf Start des Stellwerk-Simulators");
	}

}
